/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package users;

import catalog.CD;
import java.util.HashMap;
import java.util.List;

/**
 *
 * @author smoniz
 */
public class Users {

    static HashMap<String, User> Users = new HashMap<String, User>();
    static User currentUser = null;
 static  {


        UsersFromXMLHandler.getUsers();


    }
    public static boolean loggedin() {
        return currentUser != null;
    }

    public static User getCurrentUser() {
        return currentUser;
    }

    public static boolean Register(String username, String password, String name, String address, String phone) {
        User newuser = new User(username, password, name, address, phone);
      if(Users.keySet().contains(username))
          return false;
        Users.put(username, newuser);
        currentUser = newuser;
return true;

    }
    public static void addUser(User user){
        Users.put(user.getUsername(), user);

    }

    public static void removeCDs(Object[] cds) {

        for (Object cd : cds) {

            removeCD((CD) cd);
        }

    }

    public static List<CD> getWishList() {
        if (currentUser == null) {
            return null;
        }
        return currentUser.getWishList();

    }

    public static void logout() {
        currentUser = null;
    }

    public static boolean login(String username, String password) {
        try {
            if (Users.get(username).getPassword().equals(password)) {
                currentUser = Users.get(username);
                return true;

            }
        } catch (NullPointerException e) {
            return false;
        }
        return false;

    }

    public static void addCD(CD cd) {
        currentUser.addCD(cd);
    }

    public static void removeCD(CD cd) {
        currentUser.removeCD(cd);
    }
}
